package com.flats.service.transactional;



import com.flats.model.entity.Comment;
import com.flats.model.entity.Flat;
import com.flats.model.entity.Users;
import org.apache.log4j.BasicConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static void main(String[] args) throws ParseException {
//        BasicConfigurator.configure();
        ClassPathXmlApplicationContext cx=new ClassPathXmlApplicationContext("com/flats/service/context.xml");
//
        TransactionalUserService userHibernateDao= (TransactionalUserService) cx.getBean("userService");
        TransactionalFlatService flatHibernateDao= (TransactionalFlatService) cx.getBean("flatService");
        TransactionalCommentService commentHibernateDao= (TransactionalCommentService) cx.getBean("commentService");
//        System.out.println("asdffffffffffg");
//
//
        Comment newComment=new Comment();
        newComment.setText("blblabla");
        Users user = userHibernateDao.get(40L);
        System.out.println("user.getName() = " + user.getName());
        newComment.setUser(user);
        System.out.println("user stored");
        String date="06/01/2014 00:37:25";
        Date dateForSave = new SimpleDateFormat("dd/mm/yyyy hh:mm:ss").parse(date);
        newComment.setDate(dateForSave);
        System.out.println("date stored");
        Flat flat = flatHibernateDao.get(10L);
        newComment.setFlat(flat);
        System.out.println("flat stored");
        commentHibernateDao.saveOrUpdate(newComment);



    }

}
